﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using Demo.ServiceContracts.DataContracts; 
namespace Demo.Cliente
{
    public class ClientListenr : ServiceContracts.INotificationClient
    {
        public void ReciveNotification(string from, string message, ServiceContracts.DataContracts.DCClient cl)
        {
            Console.WriteLine("{0} {1} {2}", from, message, cl.FullName);
        }
    }

    class Program
    {
        private static Demo.ServiceProxy.CalculatorServiceProxy _proxy;  
        public static Demo.ServiceProxy.CalculatorServiceProxy GetProxy()
        {
            if (_proxy == null)
            {
                _proxy = new Demo.ServiceProxy.CalculatorServiceProxy("tcp_config");
            }
            else if (  _proxy.State == CommunicationState.Faulted  || _proxy.State == CommunicationState.Closed)            
            {
                _proxy = new Demo.ServiceProxy.CalculatorServiceProxy("tcp_config");
            }
            return _proxy;              
        }

        static void Main(string[] args)
        {
            Console.WriteLine("Cliente"); 
            Console.ReadLine();
            var proxy = GetProxy();

            proxy.LogOperation("test");
            try
            {
                proxy.Suma(new ServiceContracts.MessageContracts.SumaRequest() { });
                
            }
            catch (FaultException<ServiceContracts.DataContracts.DCDemoFault> ex)
            {
                Console.WriteLine(ex.Detail.UIMessage);
                Console.WriteLine(ex.Detail.SupportMessage);

            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);

            }
            
            try
            {
                proxy = GetProxy();
                proxy.Suma(new ServiceContracts.MessageContracts.SumaRequest() { });
            }
            catch (FaultException<ServiceContracts.DataContracts.DCDemoFault> ex)
            {
                Console.WriteLine(ex.Detail.UIMessage);
                Console.WriteLine(ex.Detail.SupportMessage); 

            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);

            }
            
            Console.ReadLine(); 
         
        }
    }
}
